<route lang="json5" type="page">
{
    layout: "default",
    style: {
        navigationBarTitleText: "分销商注册",
    },
}
</route>
<!-- 这个是二级分销注册界面 -->
<template>
    <view class="m-login flex flex-col items-center pt-[40rpx]">
        <!-- <view class="w-[140rpx]">
            <image src="/src/static/mp-weixin/images/login.png" mode="widthFix" />
        </view>
        <view class="u-login mt-4 w-[100%]">
            <wd-button block open-type="getUserInfo" @getuserinfo="wxLogin" :custom-style="{ background: '#07c160' }"
                >微信一键注册</wd-button
            >
        </view> -->
    </view>
</template>

<script lang="ts" setup>
import { registerUsingPost } from "@/service/app";
import { useToast } from "wot-design-uni";
import { useUserStore } from "@/store/user";
const userStore = useUserStore();
const toast = useToast();
const invitationId = ref("");

// 小程序登录
function wxLogin() {
    // if (e.errMsg != "getUserInfo:ok") {
    //     toast.error("授权失败");
    //     return;
    // }
    toast.loading({
        loadingType: "ring",
        msg: "一键注册加载中...",
    });
    uni.login({
        provider: "weixin",
        onlyAuthorize: true,
        success: function (res) {
            registerUsingPost({
                body: { code: res.code, invitationId: invitationId.value, nickName: "微信用户" },
            }).then((res) => {
                console.log(res);
                toast.close();
                userStore.clearUserInfo();
                userStore.setToken(res?.data?.token);
                userStore.setUserInfo(res?.data?.user);
                uni.switchTab({
                    url: "/pages/index/index",
                });
            });
        },
    });
}
onLoad((value) => {
    invitationId.value = decodeURIComponent(value.scene);
    wxLogin();
});
</script>

<style lang="scss" scoped>
.m-login {
    box-sizing: border-box;
    height: 100vh;
    padding: 40rpx 20rpx;
    overflow-y: auto;
    /* background: linear-gradient(135deg, #a1c4fd, #ffffff); */
}
</style>
